package com.wyclabs.auth.common;

import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * accessTokenConverter
 * @author Wyccc
 * @date 2019/10/16
 */
@Component
public class SecurityAccessTokenConverter extends DefaultAccessTokenConverter {

    @Override
    public Map<String, ?> convertAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
        Map<String, Object> map = new HashMap<>(8);
//        SecurityUser securityUser = ((SecurityUser) authentication.getPrincipal());
        //设置tokenid， 否则生成的token 和 Refresh_token 很可能是一样的
        map.put("tokenId", token.getValue());
        return map;
    }
}
